package org.cscarioni

import grails.test.*

class ChartControllerTests extends ControllerUnitTestCase {
    protected void setUp() {
        super.setUp()
    }

    protected void tearDown() {
        super.tearDown()
    }

    void testCreateChart() {
		def today=new Date()
		mockDomain(Sprint,
    			[new Sprint(name:"Sprint1",
    					estimatedTimes:
    						[new EstimatedTimeHistoryForSprint(day: (today-1),estimatedTime:90),
							 new EstimatedTimeHistoryForSprint(day:today,estimatedTime:56)]
    			           )
		        ])
		this.controller.params.entity="org.cscarioni.Sprint"
		this.controller.params.entityId="1"
		this.controller.params.propertyName="estimatedTimes"
		def serviceControl=mockFor(ChartValuesCalculatorService)
		serviceControl.demand.calculateChartMap(1..1){
			collection -> 
			assertTrue(collection.size()==2)
			def iterador = collection.iterator()
			assertEquals (90, iterador.next().estimatedTime)
			assertEquals (56, iterador.next().estimatedTime)
		}
		serviceControl.demand.calculateToZeroProgressionForDays(1..1){
			estimatedOriginal,days -> 
			assertTrue(days==2)
			assertEquals (90,estimatedOriginal)
		}
		this.controller.chartValuesCalculatorService=serviceControl.createMock()		
		this.controller.createChart()
		serviceControl.verify()
    }
}
